﻿/*
 * CoordStruct
 * 
 * initial implementation : 31.8.2007
 *
 * Copyright (c) Adam Sida, asida@centrum.cz.
 * All rights reserved.
 * 
 * for license see Petra.Gis.License.txt
 */
//using Petra.Gis.Geometry;


namespace Petra.Gis.Geometry.Support
{


  /// <summary>
  /// Structure that represents Coordinate. 
  /// For some specific cases is better to use <c>CoordStruct</c> structure than <c>Coordinate</c> class.
  /// </summary>
  public struct CoordStruct : ICoordinate
  {

    private double dX, dY, dZ;



    public CoordStruct(double x, double y, double z)
    {
      dX = x; dY = y; dZ = z;
    }





    public CoordStruct(double x, double y)
      : this(x, y, 0)
    { }




    public double X { get { return dX; } set { dX = value; } }
    public double Y { get { return dY; } set { dY = value; } }
    public double Z { get { return dZ; } set { dZ = value; } }



    public double lon { get { return dX; } set { dX = value; } }
    public double lat { get { return dY; } set { dY = value; } }





    public static bool operator !=(CoordStruct left, CoordStruct right)
    {
      return left.X != right.X || left.Y != right.Y;
    }





    public static bool operator ==(CoordStruct left, CoordStruct right)
    {
      return left.X == right.X && left.Y == right.Y;
    }




    public bool Equals(ICoordinate other, Dimension dimension)
    {
      if (dimension == Dimension.dim2D)
        return other.X == this.X && other.Y == this.Y;
      else
        return other.X == this.X && other.Y == this.Y && other.Z == this.Z;
    }




    
    public override int GetHashCode()
    {
      return base.GetHashCode();
    }





    public override bool Equals(object obj)
    {
      return base.Equals(obj);
    }




    public override string ToString()
    {
      return base.ToString() + "{" + this.X.ToString() + ";" + this.Y.ToString() + "}";
    }






    /// <summary>Parses the lat lon value.</summary>
    /// <param name="value">string value to parse</param>
    /// <remarks>It must have at least 2 parts 'degrees' 'minutes'
    /// or 3 parts 'degrees' 'minutes' 'seconds'. If it 
    /// has E/W and N/S this is used to change the sign.</remarks>
    /// <returns>instance of Coordinate structure</returns>
    public static CoordStruct Parse(string value)
    {
      Coordinate tmp = Coordinate.Parse(value);

      return new CoordStruct(tmp.X, tmp.Y, tmp.Z);
    }


  }

}
